C programming question

Status
Not open for further replies.
J

jjimenez101

Guest
hello,

I have a programming question, say I have the following C program:

main()

{

While (1)

{

if ( condition2)

{
Perform A
}

else
{
Perform B
}

Statement D

} //end while loop

} // end main loop

My question here is: will the program ever reach statementD? What I am thinking is that if condition 2 is met, it will perform A, and if not, then it will perfrom B. Then it will never get to the statement D because Im thinking that once the statement in the If section or the else section is performed, the program will go back to the begining and this process will continure for ever and not reach statment D ever.
 
Ignoring the fact that there isn't a single ; in your code.....
It will always reach Statement D because once it is done with the If/Then/Else statement, execution continues at the next statement which is D
 
Thats the answer that I was hoping for thank you.
 
Thats why indentation is recommended.

It makes it so much easier to read.
Code:
main()
{
	While (1)
	{
		if ( condition2)
		{ 
			Perform A
		}
		else
		{
			Perform B
		}
		Statement D
	} //end while loop
} // end main loop
 
sure it will reach statement D after fineshing B or finishing A programs is executed line by line and there is nothing informs that the execution should go to the beginning of the prog. without executing statement D
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…