Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

Select the output for the following set of code?

  1. static void Main(string[] args)
  2. {
  3. int i, s = 0;
  4. for (i = 1; i <= ; s = s + i, i++);
  5. {
  6. Console.WriteLine(s);
  7. }
  8. Console.ReadLine();
  9. }

 

a) Code report errorb) Code runs in infinite loop conditionc) Code gives output asd) Code give output as

user-image
Question added by Mohannad Bakbouk , Full Stack Web Developer , Almohtaseb
Date Posted: 2016/10/20
Amit Sharma
by Amit Sharma , Systems Analyst , TCS

In the below for loop statement 

for (i = 1; i <= ; s = s + i, i++) ;

{

     Console.WriteLine(s);

}

You will get compile time on the code: i <= ;

Because at the right-hand side of the condition you forgot to write any value.

Ubaid sayeed Mohd abdul sayeed
by Ubaid sayeed Mohd abdul sayeed , Senior Programmer , Moksha solutions

error saying incorrect loop condition.

Pathan Zarrar Khadar Khan
by Pathan Zarrar Khadar Khan , Windows System Administrator , Dyce Tech Pvt Ltd

a) Code report error

  1. for (i = 1; i <= ; s = s + i, i++);
  2.  no chance of it code doesn't work 
  3.  your for loop having a wrong statement  its compile time error 
  4. for loop needs three type of statements first one initialization second Condition or third is Increment 
  5. your code having more statements and in the end after the loop its ; its not valid expression 

Hassan Elsherbiny
by Hassan Elsherbiny , .Net Developer , Al-dar international

error ; i <= ; this is not valid condition 

Mohammad Nadir Roshan
by Mohammad Nadir Roshan , Technical Support Specialist , FreeBalance Co

a) Code report error:

In the condition statement of the for loop the i is not given a value to compare against so it throws error "invalid expression term".

Igor Polischuk
by Igor Polischuk , Software Engineer , EPAM

It will display 0.

 

That is everything.

Mohannad Bakbouk
by Mohannad Bakbouk , Full Stack Web Developer , Almohtaseb

No The code Working

  1. for (i = 1; i <= 10; s = s + i, i++);

More Questions Like This