In the previous articel , I was talking about conditions in c , and applying it with a simple calculator , here’s the code :
Now , it’s loops time 🙂
First , to loop is to repeat something number of times or till a certain condition like
Print my name 5 times .
Print my name till i tell you stop .
-Loops syntax :
*while loop
while(condition){
//some code goes here
}
here I’m telling him to iterate till the condition is false like
I’ll leave it to you what’s the output of this code 😉
there’s also do..while , the same as while but if you iterate with a certain number , it’ll iterate before it checks the condition , can you try to make a do…while loop ?!!
also ther’s for loop . it’s syntax is like the following
for (start ; condition; end) {
//some code goes here
}
like the following :
this code will print “hello , user” 10 times then stops .
i think you saw (i++) in the previous example , this is an increment operator , here’s some examples of increment and decrement
i++ increment by one
i– decrement by one
++i increment by one
–i decrement by one
to discuss the difference between ++i and i++ , here’s an example :
got the point ?!!
well , that’s enough for now , see you next article 🙂
We want to swim in the depth with C
go ahead 🙂
thxx
Inchallah Alaa Agwa will continue this series ,, don’t worry 😉