This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
elementos = ["a", "b", "c"] | |
print elementos.length # imprime 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$elementos = array("a", "b", "c"); | |
print count($elementos); // imprime 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def teste(idade) | |
if idade.to_i >= 18 | |
print "maior de idade: ", idade, " anos" | |
else | |
print "menor de idade: ", idde, " anos" | |
end | |
end | |
print "digite um número: " | |
idade = gets |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// declaração da variável | |
int num = 32; | |
// ok, a variável num é do tipo inteiro e tem o valor 32 | |
// atribuição de valor à variável: | |
num = 98; | |
// ok, a variável tem o valor 98 | |
num = 54.23; | |
// erro! 54.23 não é um número inteiro, então não pode ter esse valor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
num = 32; // ok, a variável num está de tipo number e tem o valor 32 | |
num = 98; // ok, a variável tem o valor 98 e ainda é do tipo number | |
document.write(typeof(num)); // imprime number | |
num = "texto"; // ok! agora num está de tipo string e tem o valor "texto" | |
document.write(typeof(num)); // imprime string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function dobro(n) { | |
return n * 2; | |
} | |
document.write(dobro(2)); // ok, imprime 4 | |
document.write(dobro("t")); // opa! "t" * 2? o que será impresso? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function dobro(n) { | |
if (typeof(n) != "number") return 0; // se n não é um número retorne 0 | |
return n * 2; | |
} | |
document.write(dobro(2)); // ok, imprime 4 | |
document.write(dobro("t")); // ok, "t" não é do tipo number, então imprime 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int dobro(int n) { | |
return n * 2; | |
} | |
int main() { | |
// ok, imprime 4 | |
cout << dobro(2); | |
// esta instrução faz com o que o código não compile | |
cout << dobro("t"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = 1 | |
b = "a" | |
c = a + b | |
TypeError: String can't be coerced into Fixnum | |
from (irb):5:in `+' | |
from (irb):5 | |
from : |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = 1 | |
b = "a" | |
c = a + b.to_i # o método to_i converte b para inteiro ("a" vale 0) | |
print c # imprime 1 |
OlderNewer