2012-06-30 14 views
12

che sto appena agli inizi con Lua, e mi chiedevo (perché non riesco a trovare sul sito web) se Lua ha un operatore OR, come come in altre lingue c'è ||:Lua ha confronti O?

if (condition == true || othercondition == false) { 
somecode.somefunction(); 
} 

mentre in Lua, c'è

if condition then 
    x = 0 
end 

come potrei scrivere un blocco IF in Lua da usare O?

risposta

20

Con "o".

if condition or not othercondition then 
    x = 0 
end 

Come afferma chiaramente il manuale Lua.

+0

Lua non ha un operatore '!'; usa invece '~' –

+1

grazie. Google mi ha fallito. – Polyov

+3

Non '~' (che è usato solo in '~ =', cioè "non è uguale a"), ma 'non'. Risolto l'esempio in risposta. –