App Inventor 2 | Control Blocks

if & if else

Kiểm tra  điều kiện. Nếu điều kiện đó đúng, sẽ thực hiện hành động bên trong "then". Nếu điều kiện sai, hành động trong "then" sẽ bị bỏ qua.


Kiểm tra điều kiện. Nếu kết quả trả về là đúng thì hành động bên trong "then" sẽ được thực hiện. Nếu kết quả trả về sai, hành động bên trong "else" sẽ được thực hiện.


Kiểm tra nếu điều kiện đúng, hành động trong "then (1)" Sẽ được thực hiện. Nếu điều kiện sai sẽ kiểm tra tiếp điều kiện trong "else if". Nếu điều kiện trả về đúng, hành động bên trong "then (2)" sẽ được thực hiện, nếu kết quả này trả về sai thì hành động trong "else" sẽ được thực hiện.






Ảnh động dưới đây sẽ cho bạn cách tạo ra block "if-else"

for each from to

Runs the blocks in the do section for each numeric value in the range starting at from and ending at to, incrementing number by the value of by each time. Use the given variable name, number to refer to the current value. You can change the name number to something else if you wish.

for each in list

Thực hiện hành động bên trong "do" cho mỗi "item" bên trong list. Chỉ định list sẽ được dùng để áp dụng cho từng thành phần (item) trong list đó. Bạn có thể thay thế tên của "item" bằng bất cứ tên gì mà bạn muốn.

while

Tests the -test condition. If true, performs the action given in -do , then tests again. When test is false, the block ends and the action given in -do is no longer performed.

if then else

Tests a given condition. If the statement is true, performs the actions in the then-return sequence of blocks and returns the then-return value; otherwise, performs the actions in the else-return sequence of blocks and returns the else-return value.

do

Sometimes in a procedure or another block of code, you may need to do something and return something, but for various reasons you may choose to use this block instead of creating a new procedure.

evaluate but ignore result

Provides a "dummy socket" for fitting a block that has a plug on its left into a place where there is no socket, such as one of the sequence of blocks in the do part of a procedure or an if block. The block you fit in will be run, but its returned result will be ignored. This can be useful if you define a procedure that returns a result, but want to call it in a context that does not accept a result.

open another screen

Mở 1 màn hình mới với tên của màn hình đó. 

open another screen with start value

Mở 1 màn hình mới và gửi kèm 1 giá trị trong "StartValue" tới màn hình đó.

get start value

Trả về giá trị "StartValue" của màn hình đã đóng trước đó.

Giá trị này được lấy từ những blok sau:  open another screen with start value hoặc  close screen with value.

close screen

Đóng màn hình hiện tại.

close screen with value

Đóng màn hình hiện tại và trả về 1 giá trị tới màn hình sẽ được mở sau khi màn hình này đóng.

close application

Thoát ứng dụng (nếu các bạn đang xem live qua Ai2 Companion thì block này không dùng được )

get plain start text

Returns the plain text that was passed to this screen when it was started by another app. If no value was passed, it returns the empty text. For multiple screen apps, use get start value rather than get plain start text

close screen with plain text

Closes the current screen and passes text to the app that opened this one. This command is for returning text to non-App Inventor activities, not to App Inventor screens. For App Inventor Screens, as in multiple screen apps, use Close Screen with Value, not Close Screen with Plain Text.