0

what is the usage of " ; " at the end of this code ?

for(int i = 1; i< 10;i++);

24th May 2021, 6:38 PM
alireza mohammadian
alireza mohammadian - avatar
10 Answers
+ 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>.
25th May 2021, 3:22 AM
Ipang
+ 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
25th May 2021, 2:35 AM
Giriraj Yalpalwar
Giriraj Yalpalwar - avatar
+ 1
The ';' was created to raise your stress levels and insult your programming skills.
26th May 2021, 4:45 PM
jovani Gittens
jovani Gittens - avatar
+ 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
27th May 2021, 8:56 AM
Giriraj Yalpalwar
Giriraj Yalpalwar - avatar
0
Thank you
24th May 2021, 7:23 PM
alireza mohammadian
alireza mohammadian - avatar
0
; helps in terminating a statement which means the line is ended
24th May 2021, 7:24 PM
Atul [Inactive]
0
Thank you for all of your answers .they are very helpful for me.
25th May 2021, 12:29 PM
alireza mohammadian
alireza mohammadian - avatar
0
For loop execute the( Initialization ; condition ; increment/decrement) ; Terminating a statement.
25th May 2021, 5:00 PM
R YUVARAJ
R YUVARAJ - avatar
0
Simba how u got the error?
26th May 2021, 5:53 PM
pavan kumar
pavan kumar - avatar
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..
27th May 2021, 5:39 PM
pavan kumar
pavan kumar - avatar