Ask and ye shall receive, here is a fairly lame example of why the single = is legal in an if. In c:
Code:
#include <stdio.h>
#include <stdlib.h>
#define LIMIT 14
int doSomething()
{
return 11;
}
int main(void)
{
int aNumber;
if((aNumber = doSomething()) > LIMIT)
{
printf("%d is greater than %d", aNumber, LIMIT);
}
else
{
printf("%d is less than %d", aNumber, LIMIT);
}
return EXIT_SUCCESS;
}
and because the inequality operators "return" a boolean the same applies to java:
Code:
public class Main {
private static int LIMIT = 14;
public static void main(String[] args)
{
int aNumber;
if((aNumber = doSomething()) > LIMIT)
{
System.out.format("%d is greater than %d\n", aNumber, LIMIT);
}
else
{
System.out.format("%d is less than %d\n", aNumber, LIMIT);
}
}
private static int doSomething()
{
return 20;
}
}