0
what is the usage of " ; " at the end of this code ?
for(int i = 1; i< 10;i++);
10 odpowiedzi
+ 5
That semicolon tells us that the for-loop is "bodyless". Meaning no extra instruction was to be carried out other than the ones inside the loop construct, which only defines and increments a local (in loop scope) counter variable <i>.
+ 2
Hey alireza mohammadian
As all said it is used to to terminate the statement , but here it is used as null statement ( ; ) !
null statement :- A statement without any executable expression !
Above " for " loop written as :
for(int i=1;i<10;i++)
; //nothing happens on this line
+ 1
The ';' was created to raise your stress levels and insult your programming skills.
+ 1
there is no error for using for(int i=1;i<10;i++) ; although it misleads the " for " but it gives correct output !
in your code " i " should declare before " for " loop , " i " after cout can't have scope of that variable ;
[edited] Simba see this
https://code.sololearn.com/cKp2BwZywW23/?ref=app
0
Thank you
0
; helps in terminating a statement which means the line is ended
0
Thank you for all of your answers .they are very helpful for me.
0
For loop execute the( Initialization ; condition ; increment/decrement)
; Terminating a statement.
0
Simba how u got the error?
0
Simba
Thirt13n all we need to run the code without any errors or warnings.
So, what we should do for that?
remove return 0 and run the code..