DAY 0 of me learning to code if i don't finish this i am gay cuck faggot. today i learned loops.

SharpOrange

SharpOrange

SUBHUMAN SHUBHAM
Joined
Jul 3, 2023
Posts
1,383
Reputation
2,839
for loop ex Print 1 to 10
while loop print till 10 stop after
do while loop

now for loop is used when you know how long you want to execute.
while has one condition till then it runs but can run infinite time also.
do while loop has also one condition but it will run one time for sure unlike while which has to satisfy the condition before it runs but do while will run one time.
as i am low iq so i got confused in do while loop so asked gpt for a eli5.

here you go

while loop


👦 Kid asks:
Is it safe to slide?
If YES → slides
If NO → doesn’t slide at all


➡️ If the condition is false, it never runs




do-while loop


👧 Kid says:
“I’m gonna slide once first
then I’ll check if I should do it again.”


➡️ Slides at least one time, no matter what




Why do we use do-while?


Because sometimes you must do something once, even if the condition is false.




Simple real-life example


🔐 Password check



do {
ask for password;
} while (password is wrong);


👉 You must ask at least once, right?
A while loop might not ask at all.

:soy: tomorrow i will do two sum and some pattern problems with loops on leetcode.
 
  • Hmm...
Reactions: Bizygomatic
for loop ex Print 1 to 10
while loop print till 10 stop after
do while loop

now for loop is used when you know how long you want to execute.
while has one condition till then it runs but can run infinite time also.
do while loop has also one condition but it will run one time for sure unlike while which has to satisfy the condition before it runs but do while will run one time.
as i am low iq so i got confused in do while loop so asked gpt for a eli5.

here you go

while loop


👦 Kid asks:
Is it safe to slide?
If YES → slides
If NO → doesn’t slide at all


➡️ If the condition is false, it never runs




do-while loop


👧 Kid says:
“I’m gonna slide once first
then I’ll check if I should do it again.”


➡️ Slides at least one time, no matter what




Why do we use do-while?


Because sometimes you must do something once, even if the condition is false.




Simple real-life example


🔐 Password check



do {
ask for password;
} while (password is wrong);


👉 You must ask at least once, right?
A while loop might not ask at all.

:soy: tomorrow i will do two sum and some pattern problems with loops on leetcode.
I read a thread which had gengars reply saying how he appreciates not choosing cs in 2023 and that even a 12yo knows how to code better than a lot of software engineers because of chatgpt @Ghost Philosophy
 
  • Love it
  • +1
Reactions: shaneywaney69 and SharpOrange
I read a thread which had gengars reply saying how he appreciates not choosing cs in 2023 and that even a 12yo knows how to code better than a lot of software engineers because of chatgpt @Ghost Philosophy
i have no other option except coding i am already a graduate there are no jobs if you don't know coding so i have to learn it anyhow
 
  • Hmm...
Reactions: Bizygomatic

Users who are viewing this thread

Back
Top