Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

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 ajoutée par Mohannad Bakbouk , Full Stack Web Developer , Almohtaseb
Date de publication: 2016/10/20
Amit Sharma
par 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
par Ubaid sayeed Mohd abdul sayeed , Senior Programmer , Moksha solutions

error saying incorrect loop condition.

Pathan Zarrar Khadar Khan
par 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
par Hassan Elsherbiny , .Net Developer , Al-dar international

error ; i <= ; this is not valid condition 

Mohammad Nadir Roshan
par 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
par Igor Polischuk , Software Engineer , EPAM

It will display 0.

 

That is everything.

Mohannad Bakbouk
par 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