WHILE TRUE
IF BUTTON() AND #X THEN
'DO SOMETHING
ENDIF
WEND
The BUTTON command can also be given a parameter. I suggest looking at the help entry. (Hover the cursor over BUTTON and press [ ? ])
Also, you can use buttons other than X. Just replace the #X with either of these:
#A #B #X #Y
#LEFT #RIGHT #UP #DOWN
#L #R
These are New 3DS only:
#ZL #ZR
You can't use START or SELECT, though.