Activity Forums Salesforce® Discussions Why is assignment within a predicate allowed in Apex?

  • Abhinav

    Member
    May 27, 2016 at 1:45 pm

    Hi Himanshu,

    There are a few cases where this behaviour is useful in e.g. Java (reading files):

    while((s = br.readLine()) != null) { ... }
    or C (strcpy):

    while ((*s++ = *s2++) != 0);
    or in Apex tests (where contact is a field of a fixture class);

    insert contact = new Contact(FirstName = 'Jane', LastName = 'Doe');

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos