Use if statement inside for loop to check if a value is positive or negative in CSharp
Description
The following code shows how to use if statement inside for loop to check if a value is positive or negative.
Example
using System; // www . ja va 2 s. c o m
public class MainClass {
public static void Main() {
int i;
for(i=-5; i <= 5; i++) {
Console.Write("Testing " + i + ": ");
if(i < 0)
Console.WriteLine("negative");
else
Console.WriteLine("positive");
}
}
}
The code above generates the following result.